package org.com.platform.core.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.com.platform.core.service.UserService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.ui.modeler.domain.Model;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName UserServiceImpl
 * @Description TODO
 * @Author SuperMen
 * Date 2019/1/11 9:09
 * @Version 1.0
 **/
@Service
public class UserServiceImpl extends FlowAbleService implements UserService {


    @Override
    public Model getModel() {
        System.out.println("model: start");
        Model model = modelService.getModel("ca3dce60-125c-11e9-bd04-408d5c0f0cb");
        byte[] bpmnXML = modelService.getBpmnXML(model);
        String modelName = model.getName();
        //文件名称必须以".bpmn20.xml"结尾否则部署 只会有 部署信息（Deployment） 没有流程定义数据（ProcessDefinition）
        if(!StringUtils.endsWith(modelName,".bpmn20.xml")){
            modelName += ".bpmn20.xml";
        }
        Deployment deployment = repositoryService.createDeployment()
                .addBytes(modelName, bpmnXML)
                .name(model.getName())
                .key(model.getKey())
                .deploy();
        List<Deployment> list = repositoryService.createDeploymentQuery().deploymentId(deployment.getId()).list();
        List<ProcessDefinition> list2 = repositoryService.createProcessDefinitionQuery()
                .deploymentId(deployment.getId()).list();

        // 设置流程分类
        for (ProcessDefinition processDefinition : list2) {
            System.out.println("******"+processDefinition);
        }
        for(Deployment Deployment:list){
            System.out.println("******"+Deployment);
        }
        return model;
    }

    @Override
    public void startActiviti() {
       // runtimeService.
    }


}
